#include <iostream>
#include "EventLoop.h"
using namespace dsth;
using namespace std;

void FunRunAt() {
    Timestamp now(Timestamp::GetNowTime());
    cout << "FunRunAt: " << now.ToFomattedString() << endl;
}

void FunRunAfterMilliSeconds() {
    Timestamp now(Timestamp::GetNowTime());
    cout << "FunRunAfterMilliSeconds: " << now.ToFomattedString() << endl;
}

void FunRunPeriodMilliSeconds() {
    Timestamp now(Timestamp::GetNowTime());
    cout << "FunRunPeriodMilliSeconds: " << now.ToFomattedString() << endl;
}

#ifdef IS_WINDOWS
static void ExitForWindows() {
    printf("::WSACleanup()\n");
    ::WSACleanup();
}
#endif

int main(int argc, char** argv) {
#ifdef IS_WINDOWS
    WSADATA wsaData;
    int err = ::WSAStartup( MAKEWORD(2,2), &wsaData );
    if( err != NO_ERROR )
        printf("Error at WSAStartup\n");
    ::atexit(ExitForWindows);
#endif

    EventLoop loop;
    Timestamp now(Timestamp::GetNowTime());
    cout << "Main: " << now.ToFomattedString() << endl;
    Timestamp runat = AddTime(now, 5);
    loop.RunAt(runat, &FunRunAt);
    loop.RunAfterMilliSeconds(10000, &FunRunAfterMilliSeconds);
    loop.RunPeriodMilliSeconds(5000, &FunRunPeriodMilliSeconds);
    loop.Loop();
    return 0;
}
